package com.beagle.njddapp.weight.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.bean.owner.OilOrderBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-13 20:13
 * ..农机加油订单 处理中
 */
public class NjOilHandleDIalog extends Dialog {

    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_user)
    TextView tvUser;
    @BindView(R.id.tv_chepai)
    TextView tvCp;
    @BindView(R.id.tv_exit)
    TextView tvExit;
    @BindView(R.id.tv_yuan)
    TextView tvYUan;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_dirver)
    TextView tvdirver;
    private NjBean njBean;
    private OilOrderBean oilOrderBean;
    public NjOilHandleDIalog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_nj_oilorder_handle);
        ButterKnife.bind(this);
        if (getWindow() != null) {
            //按空白处不能取消动画
            setCanceledOnTouchOutside(true);
            //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            //一定要在setContentView之后调用，否则无效
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            getWindow().setWindowAnimations(R.style.DialogAnim);
        }
    }
    public void update(NjBean njBean, OilOrderBean oilOrderBean) {
        this.oilOrderBean = oilOrderBean;
        tvNumber.setText("加油订单"+oilOrderBean.getOrderNum());
        tvName.setText(njBean.getMeshNum());
        tvCp.setText(oilOrderBean.getTakerCarNum());
        tvTime.setText(oilOrderBean.getArriveTime());
        tvdirver.setText(oilOrderBean.getTakerUserName()+oilOrderBean.getTakerPhone());
        tvUser.setText(oilOrderBean.getSenderName()+oilOrderBean.getSenderPhone());
        if ("finished".equals(oilOrderBean.getOrderState())){
            if (5==oilOrderBean.getPaymentType()){
                tvExit.setText("等待加油车确认收款");
                tvExit.setTextColor(Color.WHITE);
                tvExit.setBackgroundResource(R.drawable.bg_radius_4_dd);
                tvExit.setTextColor(Color.parseColor("#0049FF"));
            }else {
                tvExit.setText("线上支付");
                tvExit.setTextColor(Color.WHITE);
                tvExit.setBackgroundResource(R.drawable.bg_radius_4_blue);
            }
        }else if("confirmed".equals(oilOrderBean.getOrderState())){
            if (!TextUtils.isEmpty(oilOrderBean.getExpectArriveTime())){
                int time= (int) (Double.parseDouble(oilOrderBean.getExpectArriveTime())*60);
                if(time<1){
                    time=1;
                }
                tvExit.setText("加油车预计还有"+time+"分钟到达");
            }else {
                tvExit.setText("加油车预计还有1分钟到达");
            }
            tvExit.setBackgroundResource(R.drawable.bg_radius_2_fc);
            tvExit.setTextColor(Color.parseColor("#E56600"));
        }else {
            tvExit.setText("加油处理中");
            tvExit.setBackgroundResource(R.drawable.bg_radius_4_dd);
            tvExit.setTextColor(Color.parseColor("#0049FF"));
        }

    }
    @OnClick({R.id.container, R.id.tv_exit})
    public void onCLick(View view) {
        switch (view.getId()) {
            case R.id.container:
                dismiss();
                break;
            case R.id.tv_exit:

                break;


        }
    }



}
